package cn.edu.cimv.interceptor;

import cn.edu.cimv.constant.InfoConstant;
import cn.edu.cimv.pojo.Information;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by 门铎 on 2016/8/7.
 */
public class LoginInterceptor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String username = (String) request.getSession().getAttribute("username");
        if(username == null){
            Information information = new Information();
            information.setMessage(InfoConstant.LOGIN_ILLEGAL);
            request.setAttribute("information",information);
            request.getRequestDispatcher("/cimv/manage").forward(request,response);
            return false;
        }else{
            return true;
        }
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
